import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:screen_retriever/screen_retriever.dart';
import 'package:shimo_app/pages/index_page/index_binding.dart';
import 'package:shimo_app/pages/index_page/index_view.dart';
import 'package:shimo_app/services/service.dart';
import 'package:window_manager/window_manager.dart';

import './vision/tube_detector.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await windowManager.ensureInitialized();
  Display primaryDisplay = await screenRetriever.getPrimaryDisplay();
// 获取屏幕可用高度
  var windowHeight = primaryDisplay.visibleSize?.height ?? 800;
  var windowWidth = primaryDisplay.visibleSize?.width ?? 1280;
  WindowOptions options = WindowOptions(title: "GD-72", size: Size(1280, 800));
  windowManager.waitUntilReadyToShow(options, () async {
    await windowManager.show();
    //聚焦窗口
    await windowManager.focus();
    //ture设置窗口不可缩放 false 设置窗口可以缩放
    windowManager.setResizable(false);
  });
// windowManager.maximize();
  await initService();
  runApp(GetMaterialApp(
    theme: ThemeData(),
    getPages: [
      GetPage(name: "/", page: () => IndexPage(), binding: IndexBinding())
    ],
  ));

//外部库测试
  // final detector = TubeDetector();
  // try {
  //   // 初始化检测器
  //   for (int k = 4; k >= 0; --k) {
  //     while (detector.initialize(cameraIndex: k)) {
  //       print('检测器初始化成功');
  //       // 设置调试模式
  //       detector.setDebugMode(true);
  //       // 开始检测
  //       while (detector.startDetection()) {
  //         print('开始检测');
  //         // 处理单帧
  //         final result = detector.processSingleFrame();
  //         print('检测到 ${result.tubesWithTube.length} 个有试管的孔位');
  //         // 获取当前状态
  //         final states = detector.getCurrentTubeStates();
  //         for (final state in states) {
  //           if (state.hasTube) {
  //             print('位置 ${state.index}: 有试管 (${state.x}, ${state.y})');
  //           }
  //         }
  //         // 停止检测
  //         detector.stopDetection();
  //       }
  //     }
  //   }
  // } catch (e) {
  //   print('错误: $e');
  // } finally {
  //   detector.dispose();
  // }
}
